/**
 * common.dialog({class:"dialog-success",text:"操作成功"});
 * common.dialog({class:"dialog-warn",text:"非法操作"});
 * common.confirm({btnLeft:"单按钮",text:"操作成功"});
 * common.confirm({btnLeft:"左按钮",btnRight:"右按钮",title:"标题",content:"提示内容",callbackLeft:function () {},callbackRight:function () {}});
 * common.loading();
 * common.loading("带文字的加载中");
 * common.closeLoading();
 **/
var common = {
    calcuPostion: function (dialog) {
        $(dialog).css("visibility", "hidden");
        var de = document.documentElement;
        var selfWidth = $(dialog).offset().width;
        var selfHeight = $(dialog).offset().height;
        $(dialog).css({
            "left": (de.clientWidth - selfWidth) / 2 + "px",
            "top": (de.clientHeight - selfHeight) / 2 + "px",
        });
        $(dialog).css("visibility", "visible");
    },
    dialog: function (param) {
        if ($("." + param.class).length === 0) {
            var icon = param.class === "dialog-success" ? "icon-agree" : "icon-ico_warning";
            var template = '<div class="' + param.class + '"><i class="' + icon + '"></i><span>' + param.text + '</span></div>';
            $("body").append(template);
        } else {
            $("." + param.class).find("span").text(param.text);
        }
        if ($("." + param.class).css("visibility") != "hidden") {
            return;
        }
        ;
        var $this = $("." + param.class);
        $this.css("visibility", "visible");
        var timerId = setTimeout(function () {
            $this.css("visibility", "hidden");
            param.callback && param.callback();
            clearTimeout(timerId);
        }, param.time ? param.time : 2000);
       // this.calcuPostion($this);
    },
    confirm: function(param) {
        param.btnLeft = (param.btnLeft == undefined ? "" : param.btnLeft);
        param.content = (param.content == undefined ? "提示内容" : param.content);
        param.title = (param.title == undefined ? "标题" : param.title);
        param.layer = (param.layer == false ? '' : '<div id="layer" class="layer"></div>');

        var form = (param.form == undefined ? "" : " " + param.form);
        var btnStr = '<span class="confirm-cancel">' + param.btnLeft + '</span><span class="confirm-sure">' + param.btnRight + '</span>';
        if (param.btnRight == undefined) {
            btnStr = '<span class="confirm-sure2">' + param.btnLeft + '</span>';
        }
        var template = param.layer +
            '<div class="dialog-confirm' + form + '">' +
            '<div class="confirm-content"><span class="confirm-title">' + param.title + '</span><div class="inner-content">' + param.content + '</div></div>' +
            '<p class="confirm-operate clearfix">' + btnStr + '</p>'
        '</div>';
        var attach = (param.attach == undefined ? $("body") : param.attach);
        attach.append(template);

        $(".dialog-confirm .confirm-operate>*").on("click", function(e) {
            e.preventDefault();
            var $this=$(this);
            var $dialog = $this.parents(".dialog-confirm");
            var $layer = $dialog.prev(".layer");
            if($this.hasClass("confirm-cancel")||$this.hasClass("confirm-sure2"))
            {
                param.callbackLeft && param.callbackLeft();
            }
            if($this.hasClass("confirm-sure"))
            {
                param.callbackRight && param.callbackRight();
            }
            $this.off();
            param.layer&&$layer.remove();
            $dialog.remove();
        });
    },
    loading: function (text) {
        $(".loading-wrap").remove();
        if (text !== undefined) {
            var template = '<div class="loading-wrap"><div class="layer-opcity"></div><div class="loading contain-text">' + '<div class="continer"><div class="loading-icon">' + '<div class="text">' + text + '</div></div></div></div></div>';
            $("body").append(template);
        } else {
            var template = '<div class="loading-wrap"><div class="loading">' + '<div class="continer"><div class="loading-icon"></div></div></div></div>'
            $("body").append(template);
        }
       // this.calcuPostion($(".loading"));
    },
    closeLoading: function () {
        $(".loading-wrap").remove();
    }
}
$(function () {
    //点击清除按钮清空文本框内容
    $(document).on('blur ', 'input', function (e) {
        var $this = $(this);
        var temp_timer = setTimeout(function () {
            $this.next(".zhk-list_gb").hide();
            clearTimeout(temp_timer);
        }, 10)
    });
    $(document).on('focus input ', 'input', function () {
        $("input[required]").next(".zhk-list_gb").hide();
        $(this).val().length > 0 && $(this).next(".zhk-list_gb").show();
    });
    $(document).on('click', 'input+.zhk-list_gb', function () {
        $(this).prev("input").val("");
        $(this).trigger("clearInput");
    });
});







